#pragma once
#include <WinSock2.h>
#include <Windows.h>
#include <iostream>

#pragma comment(lib,"ws2_32.lib")

#define CPP_11_THREAD true
#define WINDOWS_THREAD false

#define THREAD_TYPE CPP_11_THREAD

struct SHARESOCKETDATA
{
	SOCKET s;
	SOCKADDR_IN sAddr;
};

struct SHAREIODATA
{
	OVERLAPPED ol;
	char buf[2048];
};

class BROKEN_IOCP
{
public:
	BROKEN_IOCP();
	~BROKEN_IOCP();

	BOOL BindAndListen(int port);

	SOCKET GetServerSocket() { return m_serverSocket; };
	HANDLE GetIOCPHandle() { return m_hIOCP; };

private:
	WSADATA m_wsaData;
	HANDLE m_hIOCP;
	SOCKET m_serverSocket;
	SOCKADDR_IN m_serverAddr;
};

#if THREAD_TYPE 
void IOCP_WorkThread(BROKEN_IOCP * iocp);
void IOCP_AcceptThread(BROKEN_IOCP *iocp);
#else // 
void WINAPI IOCP_WorkThread(BROKEN_IOCP * iocp);
void WINAPI IOCP_AcceptThread(BROKEN_IOCP *iocp);
#endif

